package com.irdstudio.efp.riskm.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.riskm.service.dao.PspCheckRptDao;
import com.irdstudio.efp.riskm.service.domain.PspCheckRpt;
import com.irdstudio.efp.riskm.service.facade.PspCheckRptService;
import com.irdstudio.efp.riskm.service.vo.PspCheckRptVO;
/**
 * <p>ServiceImpl: 贷后检查报告表				<p>
 * @author chenqm1
 * @date 2018-05-07
 */
@Service("pspCheckRptService")
public class PspCheckRptServiceImpl implements PspCheckRptService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PspCheckRptServiceImpl.class);

	@Autowired
	private PspCheckRptDao pspCheckRptDao;
	
	/**
	 * 新增操作
	 */
	public int insertPspCheckRpt(PspCheckRptVO inPspCheckRptVo) {
		logger.debug("当前新增数据为:"+ inPspCheckRptVo.toString());
		int num = 0;
		try {
			PspCheckRpt pspCheckRpt = new PspCheckRpt();
			beanCopy(inPspCheckRptVo, pspCheckRpt);
			num = pspCheckRptDao.insertPspCheckRpt(pspCheckRpt);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PspCheckRptVO inPspCheckRptVo) {
		logger.debug("当前删除数据条件为:"+ inPspCheckRptVo);
		int num = 0;
		try {
			PspCheckRpt pspCheckRpt = new PspCheckRpt();
			beanCopy(inPspCheckRptVo, pspCheckRpt);
			num = pspCheckRptDao.deleteByPk(pspCheckRpt);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPspCheckRptVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PspCheckRptVO inPspCheckRptVo) {
		logger.debug("当前修改数据为:"+ inPspCheckRptVo.toString());
		int num = 0;
		try {
			PspCheckRpt pspCheckRpt = new PspCheckRpt();
			beanCopy(inPspCheckRptVo, pspCheckRpt);
			num = pspCheckRptDao.updateByPk(pspCheckRpt);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPspCheckRptVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PspCheckRptVO queryByPk(PspCheckRptVO inPspCheckRptVo) {
		
		logger.debug("当前查询参数信息为:"+ inPspCheckRptVo);
		try {
			PspCheckRpt queryPspCheckRpt = new PspCheckRpt();
			beanCopy(inPspCheckRptVo, queryPspCheckRpt);
			PspCheckRpt queryRslPspCheckRpt = pspCheckRptDao.queryByPk(queryPspCheckRpt);
			if (Objects.nonNull(queryRslPspCheckRpt)) {
				PspCheckRptVO outPspCheckRptVo = beanCopy(queryRslPspCheckRpt, new PspCheckRptVO());
				logger.debug("当前查询结果为:"+ outPspCheckRptVo.toString());
				return outPspCheckRptVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PspCheckRptVO> queryAllOwner(PspCheckRptVO pspCheckRptVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PspCheckRptVO> list = null;
		try {
			List<PspCheckRpt> pspCheckRpts = pspCheckRptDao.queryAllOwnerByPage(pspCheckRptVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pspCheckRpts.size());
			pageSet(pspCheckRpts, pspCheckRptVo);
			list = (List<PspCheckRptVO>) beansCopy(pspCheckRpts, PspCheckRptVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PspCheckRptVO> queryAllCurrOrg(PspCheckRptVO pspCheckRptVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PspCheckRpt> pspCheckRpts = pspCheckRptDao.queryAllCurrOrgByPage(pspCheckRptVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pspCheckRpts.size());
		List<PspCheckRptVO> list = null;
		try {
			pageSet(pspCheckRpts, pspCheckRptVo);
			list = (List<PspCheckRptVO>) beansCopy(pspCheckRpts, PspCheckRptVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PspCheckRptVO> queryAllCurrDownOrg(PspCheckRptVO pspCheckRptVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PspCheckRpt> pspCheckRpts = pspCheckRptDao.queryAllCurrDownOrgByPage(pspCheckRptVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pspCheckRpts.size());
		List<PspCheckRptVO> list = null;
		try {
			pageSet(pspCheckRpts, pspCheckRptVo);
			list = (List<PspCheckRptVO>) beansCopy(pspCheckRpts, PspCheckRptVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}

	@Override
	public PspCheckRptVO queryByBizSerno(PspCheckRptVO pspCheckRptVo){
		logger.debug("当前查询参数信息为:"+ pspCheckRptVo.getBizSerno());
		try {
			PspCheckRpt queryPspCheckRpt = new PspCheckRpt();
			beanCopy(pspCheckRptVo, queryPspCheckRpt);
			PspCheckRpt queryRslPspCheckRpt = pspCheckRptDao.queryByBizSerno(queryPspCheckRpt);
			if (Objects.nonNull(queryRslPspCheckRpt)) {
				PspCheckRptVO outPspCheckRptVo = beanCopy(queryRslPspCheckRpt, new PspCheckRptVO());
				logger.debug("当前查询结果为:"+ outPspCheckRptVo.toString());
				return outPspCheckRptVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

}
